Ext.define('PackageManager.rules.RuleEngine', {
    singleton: true,
    ruleContainer: new Ext.util.HashMap(),

    register: function(rule) {
        var ruleContainer = PackageManager.rules.RuleEngine.ruleContainer;
        var ruleComponentKeys = rule.componentKeys;
        Ext.Array.each(ruleComponentKeys, function(key, index, countriesItSelf) {
            var rules = ruleContainer.get(key);
            if (rules) {
                rules[rules.length] = rule;
                ruleContainer.add(key, rules);
            }
            else {
                rules = [rule];
                ruleContainer.add(key, rules);
            }
        });
    },
    process: function(activeComponentKey) {
        var rules = PackageManager.rules.RuleEngine.ruleContainer.get(activeComponentKey);
        Ext.Array.each(rules, function(rule, index, countriesItSelf) {
            if (rule.condition()) {
                rule.action();
            };
        });
    }
});
